class Solution {
public:
    void dfs(vector<vector<char>>& board, int x, int y) {

        board[x][y] = '*';
        if (x - 1 >= 0 && board[x - 1][y] == 'O')
            dfs(board, x - 1, y);
        if (x + 1 < board.size() && board[x + 1][y] == 'O')
            dfs(board, x + 1, y);
        if (y - 1 >= 0 && board[x][y - 1] == 'O')
            dfs(board, x, y - 1);
        if (y + 1 < board[0].size() && board[x][y + 1] == 'O')
            dfs(board, x, y + 1);
    }
    void solve(vector<vector<char>>& board) {
        // 这是一个涂色问题 但是有点小坑 如果遇见o
        // 要判断上下左右是不是有边界点o或者是与边界相邻的o
        // 只有没有与这些相邻的才可以填充
        // 先把边界相邻的改了 剩下的就是可以变成X的 然后再还原
        int nr = board.size();
        if (!nr)
            return;
        int nc = board[0].size();
        for (int i = 0; i < nr; ++i) {
            if (board[i][0] == 'O')
                dfs(board, i, 0);
            if (board[i][nc - 1] == 'O')
                dfs(board, i, nc - 1);
        }
        for (int j = 1; j < nc - 1; ++j) {
            if (board[0][j] == 'O')
                dfs(board, 0, j);
            if (board[nr - 1][j] == 'O')
                dfs(board, nr - 1, j);
        }
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                if (board[i][j] == 'O') {
                    board[i][j] = 'X';
                } else if (board[i][j] == '*') {
                    board[i][j] = 'O';
                }
            }
        }
    }
};
